#!/usr/bin/python

import os
import sqlite3

database = 'store.db'

def initialize_database():
	global database

	try:
		conn = sqlite3.connect(database)
		
		# Create table
		query = query_generator("CREATE", "customer", "(ID INT PRIMARY KEY NOT NULL, FIRST_NAME TEXT NOT NULL, LAST_NAME TEXT NOT NULL)")
		create_table(conn, query)
		delete_table(conn, "customer")
		conn.close()

	except Exception as e:
		print "Error: ", e

def query_generator(action, table, command):
	try:
		return action + " TABLE " + table + " " + command
	except Exception as e:
		raise e
	
def create_table(db_conn, table):
	try:	
		db_conn.execute(table)
		db_conn.commit()
		print "Table customer create successfully"
	except Exception as e:
		raise e

def delete_table(db_conn, table):
	try: 
		db_conn.execute("DROP TABLE " + table)
		db_conn.commit()
		print "Table " + table + " deleted succesfully"
	except Exception as e:
		raise e

if __name__ == '__main__':
	initialize_database()
